package cn.tedu.basic;

import javax.swing.text.html.HTMLDocument;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;

//测试LinkList,底层是一个链表，增删快，查询慢，每个元素叫node，
// 靠prev绑定前面一个元素维护关系，next绑定后面一个元素维护关系
public class Test2_LinkedList {
    public static void main(String[] args) {
        //创建对象
        LinkedList lk =new LinkedList();
        //调用方法
        lk.add(88);
        lk.add(89);
        lk.add(90);
        lk.add(88);
        lk.add(100);
        lk.add(null);
        lk.addFirst(87);
        lk.addLast(88);
        lk.add(null);
        System.out.println(lk);
        System.out.println(lk.get(5));
        System.out.println(lk.getFirst());
        System.out.println(lk.getLast());
        System.out.println(lk.removeFirst());
        System.out.println(lk.removeLast());
        lk.offer(66);
        lk.offerFirst(77);
        lk.offerLast(55);
        System.out.println(lk);
        System.out.println(lk.peek());
        System.out.println(lk.peekFirst());
        System.out.println(lk.peekLast());
        System.out.println(lk.pollFirst());
        System.out.println(lk.pollLast());
        //有序 可重复，可存多个null,迭代
        Iterator it =lk.iterator();
        while (it.hasNext()){
            Object o =it.next();
            System.out.println(o);
        }
        ListIterator it1=lk.listIterator();
        while (it1.hasPrevious()){
            Object o=it1.previous();
            System.out.println(o);
        }
        while (it1.hasNext()){
            Object o =it1.next();
            System.out.println(o);
        }
        for(Object o : lk){
            System.out.println(lk);
        }
    }
}
